package com.fqgj.sentry.biz.mc;

import com.fqgj.sentry.biz.mc.vo.application.ApplicationVo;
import com.fqgj.sentry.biz.mc.vo.role.RoleVo;
import com.fqgj.sentry.manage.entity.McApplicationEntity;
import com.fqgj.sentry.manage.entity.McRoleEntity;
import com.fqgj.sentry.manage.service.ApplicationService;
import com.fqgj.sentry.manage.service.RoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by ykpbean kangping.ying@yuntu-inc.com
 *
 * @description
 * @create 2017-07-27 上午10:12
 */

@Component
public class ComboBoxBusiness {
    @Autowired
    private RoleService roleService;
    @Autowired
    private ApplicationService applicationService;

    public List<RoleVo> queryRoleComboBox(Long merchantId) {
        List<McRoleEntity> roleEntityList = roleService.selectListByMerchant(merchantId);
        List<RoleVo> roleVoList=new ArrayList<>();
        for (McRoleEntity entity : roleEntityList) {
            RoleVo roleVo=new RoleVo();
            BeanUtils.copyProperties(entity,roleVo);
            roleVoList.add(roleVo);
        }
        return roleVoList;
    }

    public List<ApplicationVo> queryAppComboBox(Long merchantId) {
        List<McApplicationEntity> applicationEntityList = applicationService.selectApplicationList(merchantId);
        List<ApplicationVo> applicationVoList = new LinkedList<>();
        for (McApplicationEntity appEntity : applicationEntityList) {
            ApplicationVo applicationVo = new ApplicationVo()
                    .setAppId(appEntity.getId())
                    .setAppCode(appEntity.getAppCode())
                    .setAppName(appEntity.getAppName());
            applicationVoList.add(applicationVo);
        }
        return applicationVoList;
    }
}
